package cn.ctodb.im.dto.auth;

import cn.ctodb.im.dto.AbstractDTO;
import cn.ctodb.im.proto.Auth;

/**
 * All rights Reserved, Designed By www.ctodb.cn
 *
 * @version V1.0
 * @author: lichaohn@163.com
 * @date: 2018-11-12 16:24
 * @Copyright: 2018 www.ctodb.cn All rights reserved.
 */
public class AuthRespDTO extends AbstractDTO<Auth.AuthResp> {

    @Override
    public void fromProto(Auth.AuthResp authResp) {
        setStatus(Status.valueOf(authResp.getStatus().name()));
        setErrMsg(authResp.getErrMsg());
        setErrorCode(authResp.getErrorCode());
    }

    @Override
    public Auth.AuthResp toProto() {
        return Auth.AuthResp.newBuilder().setStatus(getAuthStatus()).setErrorCode(getErrorCode()).setErrMsg(getErrMsg()).build();
    }

    private Auth.AuthResp.Status getAuthStatus() {
        try {
            return Auth.AuthResp.Status.valueOf(getStatus().name());
        } catch (Exception e) {
            return Auth.AuthResp.Status.ERROR;
        }
    }
}
